﻿using Hammock.Web;
using Weibo4Sharp.Model;

namespace Weibo4Sharp.Service
{   
	public partial class WeiboService
	{
        public virtual WeiboUser FollowUser(long userId)
        {
            return WithHammock<WeiboUser>(WebMethod.Post, "friendships/create", FormatAsString, "?user_id=", userId);
        }

        public virtual WeiboUser FollowUser(string screenName)
        {
            return WithHammock<WeiboUser>(WebMethod.Post, "friendships/create", FormatAsString, "?screen_name=", screenName);
        }

        public virtual WeiboUser UnfollowUser(long userId)
        {
            return WithHammock<WeiboUser>(WebMethod.Delete, "friendships/destroy", FormatAsString, "?user_id=", userId);
        }

        public virtual WeiboUser UnfollowUser(string screenName)
        {
            return WithHammock<WeiboUser>(WebMethod.Delete, "friendships/destroy", FormatAsString, "?screen_name=", screenName);
        }

        public virtual WeiboRelationship GetFriendshipInfo(string targetScreenName)
        {
            return WithHammock<WeiboRelationship>("friendships/show", FormatAsString, "?target_screen_name=", targetScreenName);
        }

        public virtual WeiboRelationship GetFriendshipInfo(string sourceScreenName, string targetScreenName)
        {
            return WithHammock<WeiboRelationship>("friendships/show", FormatAsString, "?source_screen_name=", sourceScreenName, "&target_screen_name=", targetScreenName);
        }

        public virtual WeiboRelationship GetFriendshipInfo(long targetId)
        {
            return WithHammock<WeiboRelationship>("friendships/show", FormatAsString, "?target_id=", targetId);
        }

        public virtual WeiboRelationship GetFriendshipInfo(long sourceId, long targetId)
        {
            return WithHammock<WeiboRelationship>("friendships/show", FormatAsString, "?source_id=", sourceId, "&target_id=", targetId);            
        }

        /// <summary>
        /// check whether target is a friend of source
        /// </summary>
        /// <param name="sourceId">source user id</param>
        /// <param name="targetId">target user id</param>
        /// <returns></returns>
        public virtual WeiboFriendExist VerifyFriendship(long sourceId, long targetId)
        {
            return WithHammock<WeiboFriendExist>("friendships/exists", FormatAsString, "?user_a=", sourceId, "&user_b=", targetId);
        }
	}
}
